Skip to content

tool_communication.py: Add error handling for non-existing parent#477

Merged
urfeex merged 3 commits intoUniversalRobots:masterfrom
urfeex:tool_comm_error_handling_nonexistent_path
Mar 31, 2026
Merged

tool_communication.py: Add error handling for non-existing parent#477
urfeex merged 3 commits intoUniversalRobots:masterfrom
urfeex:tool_comm_error_handling_nonexistent_path

Conversation

@urfeex
Copy link
Copy Markdown
Member

@urfeex urfeex commented Mar 30, 2026

When passing a path as a local device name where the parent directory doesn't exist, socat complains about the link target not existing. From that it isn't necessary clear that this means that the parent directory doesn't exist. This commit adds a check for that case explicitly with a clear error message.

Without this PR

Without the changes from this PR passing a non-existing parent folder will look like this:

$ scripts/tool_communication.py --device-name /tmp/path/doesnt/exist/ttyUR 192.168.178.103
[INFO] Robot IP: 192.168.178.103
[INFO] TCP Port: 54321
[INFO] Configuring PTY symlink at '/tmp/path/doesnt/exist/ttyUR'
[INFO] Starting socat with following command:
socat pty,link=/tmp/path/doesnt/exist/ttyUR,raw,ignoreeof,waitslave tcp:192.168.178.103:54321
2026/03/30 11:19:16 socat[59904] E symlink("/dev/pts/11", "/tmp/path/doesnt/exist/ttyUR"): No such file or directory
[INFO] Socat terminated

With this PR

With the changes from this PR passing a non-existing parent folder will look like this:

$ scripts/tool_communication.py --device-name /tmp/path/doesnt/exist/ttyUR 192.168.178.103
[INFO] Robot IP: 192.168.178.103
[INFO] TCP Port: 54321
[ERROR] Parent directory '/tmp/path/doesnt/exist' does not exist.
Socat needs an existing directory to create the PTY symlink.
Fix:
  - Create the parent directory, e.g. 'mkdir -p /tmp/path/doesnt/exist'.
  - Use a different device name with an existing parent directory.
[INFO] Exiting tool communication script.

When passing a path as a local device name where the parent directory
doesn't exist, socat complains about the link target not existing. From
that it isn't necessary clear that this means that the **parent**
directory doesn't exist. This commit adds a check for that case
explicitly with a clear error message.
@urfeex urfeex requested a review from a team March 30, 2026 09:25
@urfeex urfeex added the enhancement New feature or request label Mar 30, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 86.66667% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.90%. Comparing base (4740f63) to head (e801e30).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
scripts/tool_communication.py 86.66% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #477      +/-   ##
==========================================
- Coverage   77.04%   76.90%   -0.14%     
==========================================
  Files         110      111       +1     
  Lines        5824     5902      +78     
  Branches     2577     2576       -1     
==========================================
+ Hits         4487     4539      +52     
- Misses        997     1023      +26     
  Partials      340      340              
Flag Coverage Δ
python_scripts 75.90% <86.66%> (?)
start_ursim 83.08% <ø> (-1.48%) ⬇️
ur20-latest 72.29% <ø> (-0.01%) ⬇️
ur5-3.14.3 72.11% <ø> (-0.16%) ⬇️
ur5e-10.11.0 66.16% <ø> (+0.20%) ⬆️
ur5e-10.12.0 66.99% <ø> (-0.32%) ⬇️
ur5e-10.7.0 65.13% <ø> (-0.34%) ⬇️
ur5e-5.9.4 72.57% <ø> (-0.28%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@urfeex urfeex marked this pull request as draft March 30, 2026 09:43
@urfeex urfeex marked this pull request as ready for review March 30, 2026 10:37
@urfeex urfeex force-pushed the tool_comm_error_handling_nonexistent_path branch from a171ecb to e801e30 Compare March 30, 2026 10:47
Copy link
Copy Markdown
Contributor

@srvald srvald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Thank you for improving the error handling by switching to exceptions and for adding tests.
The additional check ensuring that the parent directory exists makes sense and is something I hadn't taken into account, so thanks for adding that error case.

@urfeex urfeex merged commit 343e5ca into UniversalRobots:master Mar 31, 2026
36 of 39 checks passed
@urfeex urfeex deleted the tool_comm_error_handling_nonexistent_path branch March 31, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants